<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('盈利预测') }}</span>
    </div>
    <!--所有列都加 type="" 的原因是消除树状图默认展开后的收起箭头-->
    <el-table v-loading="loading" :data="dealPredictList" border row-key="id" default-expand-all type="">
      <el-table-column :label="$t('指标')" align="left" prop="indicators" min-width="50" type="">
        <template slot-scope="scope" type="">
          <div :class="scope.row.parentId !== '0' ? 'indicators':''" type="">{{ scope.row.indicators }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" min-width="100" type="">
        <template slot-scope="scope">
          <el-input v-if="scope.row.parentId !== '0'" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" type="">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.parentId !== '0'"
            v-hasPermi="['deal:indicator:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { findDealPredict, delDealIndicatorPredict } from '@/api/deal/indicator/dealIndicatorPredict'
  export default {
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 盈利预测表格数据
        dealPredictList: [],
        // 弹出层标题
        title: '盈利预测',
        // 是否显示弹出层
        formOpen: false,
        // 当前父级别
        parentGrade: '0',
        // 查询参数
        queryParams: {
          parentId: '0',
          pageNum: 1,
          pageSize: 10
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询盈利预测列表 */
      getList() {
        this.loading = true
        findDealPredict(this.queryParams).then(response => {
          this.dealPredictList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,

          parentId: undefined,

          grade: undefined,

          indicators: undefined,

          sort: undefined,

          remark: undefined,

          createBy: undefined,

          createTime: undefined,

          updateBy: undefined,

          updateTime: undefined,

          delFlag: undefined
        }
        this.resetForm('form')
      },
      /** 删除按钮操作 */
      deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(function() {
          return delDealIndicatorPredict(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .indicators{
    padding-left: 30px;
  }
</style>
